package com.weiyuwqj.app.mobile.debt;

import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.constant.Message;
import com.weiyuwqj.api.model.BasDebt;
import com.weiyuwqj.api.service.BasDebtService;
import com.weiyuwqj.api.util.IpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhangyong on 2017/3/22.
 * 债权
 */
@Controller
@RequestMapping("/mobile/user/debt")
public class MobileDebtController {

    @Autowired
    private BasDebtService debtService;

    /**
     * 添加债权
     * @param debt 债权对象
     * @return 添加结果
     */
    @ResponseBody
    @RequestMapping(value = "/addDebt",method = RequestMethod.POST)
    public Object addDebt(BasDebt debt){
        debt.setAddip(IpUtils.get());
        debtService.addDebt(debt);
        return Message.OK;
    }

    /**
     * 获取债权详情
     * @param debtId 债权ID
     * @return 债权详情
     */
    @ResponseBody
    @RequestMapping(value = "/getDebtInfo",method = RequestMethod.POST)
    public Object getDebtInfo(Integer debtId) {
        try {
            return debtService.getDebtById(debtId);
        } catch (Exception e) {
            return Message.FAIL;
        }
    }

//    /**
//     * 查询债权列表
//     * @param p     分页参数
//     * @return 债权列表
//     */
//    @ResponseBody
//    @RequestMapping(value = "/getDebtList",method = RequestMethod.POST)
//    public Object getDebtList(Paginator p,
//                              String beginDate,
//                              String endDate,
//                              String userId){
//        Map map = new HashMap();
//        map.put("beginDate",beginDate);
//        map.put("endDate",endDate);
//        map.put("userId",userId);
//        return debtService.debtList(p,map);
//    }
}
